package com.gec.zhs.controller;

import java.util.List;

import com.gec.zhs.entity.query.CategoryQuery;
import com.gec.zhs.entity.po.Category;
import com.gec.zhs.entity.vo.ResponseVO;
import com.gec.zhs.service.CategoryService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 分类表，也可用作数据字典。表示一个全集，比如：男、女、未知。关联的分类类型表示按什么进行的分类，如：按照性别对人类对象集 Controller
 */
@RestController("categoryController")
@RequestMapping("/category")
public class CategoryController extends ABaseController{

	@Resource
	private CategoryService categoryService;
	/**
	 * 根据条件分页查询
	 */
	@RequestMapping("/loadDataList")
	public ResponseVO loadDataList(CategoryQuery query){
		return getSuccessResponseVO(categoryService.findListByPage(query));
	}

	/**
	 * 新增
	 */
	@RequestMapping("/add")
	public ResponseVO add(Category bean) {
		categoryService.add(bean);
		return getSuccessResponseVO(null);
	}

	/**
	 * 批量新增
	 */
	@RequestMapping("/addBatch")
	public ResponseVO addBatch(@RequestBody List<Category> listBean) {
		categoryService.addBatch(listBean);
		return getSuccessResponseVO(null);
	}

	/**
	 * 批量新增/修改
	 */
	@RequestMapping("/addOrUpdateBatch")
	public ResponseVO addOrUpdateBatch(@RequestBody List<Category> listBean) {
		categoryService.addBatch(listBean);
		return getSuccessResponseVO(null);
	}

	/**
	 * 根据Id查询对象
	 */
	@RequestMapping("/getCategoryById")
	public ResponseVO getCategoryById(String id) {
		return getSuccessResponseVO(categoryService.getCategoryById(id));
	}

	/**
	 * 根据Id修改对象
	 */
	@RequestMapping("/updateCategoryById")
	public ResponseVO updateCategoryById(Category bean,String id) {
		categoryService.updateCategoryById(bean,id);
		return getSuccessResponseVO(null);
	}

	/**
	 * 根据Id删除
	 */
	@RequestMapping("/deleteCategoryById")
	public ResponseVO deleteCategoryById(String id) {
		categoryService.deleteCategoryById(id);
		return getSuccessResponseVO(null);
	}
}